// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.ai.states;

import java.util.HashMap;
import org.joml.Vector3f;
import zombie.ai.State;
import zombie.audio.parameters.ParameterZombieState;
import zombie.characters.IsoGameCharacter;
import zombie.characters.IsoPlayer;
import zombie.characters.IsoZombie;
import zombie.gameStates.IngameState;
import zombie.iso.Vector2;
import zombie.util.Type;

public class LungeNetworkState extends State {
    static LungeNetworkState _instance = new LungeNetworkState();
    private Vector2 temp = new Vector2();
    private final Vector3f worldPos = new Vector3f();
    private static final Integer PARAM_TICK_COUNT = 0;

    public static LungeNetworkState instance() {
        return _instance;
    }

    @Override
    public void enter(IsoGameCharacter owner) {
        HashMap hashMap = owner.getStateMachineParams(this);
        WalkTowardNetworkState.instance().enter(owner);
        IsoZombie isoZombie = (IsoZombie)owner;
        isoZombie.LungeTimer = 180.0F;
        hashMap.put(PARAM_TICK_COUNT, IngameState.instance.numberTicks);
    }

    @Override
    public void execute(IsoGameCharacter owner) {
        WalkTowardNetworkState.instance().execute(owner);
        IsoZombie isoZombie = (IsoZombie)owner;
        owner.setOnFloor(false);
        owner.setShootable(true);
        if (isoZombie.bLunger) {
            isoZombie.walkVariantUse = "ZombieWalk3";
        }

        isoZombie.LungeTimer = isoZombie.LungeTimer - zombie.GameTime.getInstance().getMultiplier() / 1.6F;
        IsoPlayer isoPlayer = Type.tryCastTo(isoZombie.getTarget(), IsoPlayer.class);
        if (isoPlayer != null && isoPlayer.isGhostMode()) {
            isoZombie.LungeTimer = 0.0F;
        }

        if (isoZombie.LungeTimer < 0.0F) {
            isoZombie.LungeTimer = 0.0F;
        }

        if (isoZombie.LungeTimer <= 0.0F) {
            isoZombie.AllowRepathDelay = 0.0F;
        }

        HashMap hashMap = owner.getStateMachineParams(this);
        long _long = (Long)hashMap.get(PARAM_TICK_COUNT);
        if (IngameState.instance.numberTicks - _long == 2L) {
            ((IsoZombie)owner).parameterZombieState.setState(ParameterZombieState.State.LockTarget);
        }
    }

    @Override
    public void exit(IsoGameCharacter owner) {
        WalkTowardNetworkState.instance().exit(owner);
    }

    @Override
    public boolean isMoving(IsoGameCharacter owner) {
        return true;
    }
}
